#!/bin/bash

# ============================================
# 深度排查 Nginx 代理 404 问题
# ============================================

echo "=== 检查 Nginx 配置 ==="
cat /etc/nginx/conf.d/frontend.conf | grep -A 5 "location /api/"

echo ""
echo "=== 测试后端直接访问 ==="
curl -v http://127.0.0.1:8000/api/login/ 2>&1 | grep -E "HTTP|Content-Type|Location|Host" | head -5

echo ""
echo "=== 测试后端根路径 ==="
curl -v http://127.0.0.1:8000/ 2>&1 | grep -E "HTTP|Content-Type" | head -3

echo ""
echo "=== 查看 Nginx 错误日志 ==="
sudo tail -20 /var/log/nginx/frontend_error.log | grep -v "favicon"

echo ""
echo "=== 查看 Nginx 访问日志 ==="
sudo tail -5 /var/log/nginx/frontend_access.log

echo ""
echo "=== 检查 Nginx 进程和配置 ==="
sudo nginx -T 2>/dev/null | grep -A 10 "location /api/" | head -15

echo ""
echo "=== 测试不同路径 ==="
echo "测试 /api/init/settings/:"
curl -s -o /dev/null -w "HTTP: %{http_code}\n" http://127.0.0.1/api/init/settings/

echo "测试 /api/captcha/:"
curl -s -o /dev/null -w "HTTP: %{http_code}\n" http://127.0.0.1/api/captcha/

